<template>
  <form id="login-form">
    <div style="margin-left: 27px; display: block">
      <div class="input-group reg-login-div">
                    <span class="input-group-addon icon-user" id="basic-addon1">
                    </span>
        <input v-model="account" name="account" type="text" class="form-control login-input" style="width: 262px"
               placeholder="用户名" aria-describedby="basic-addon1">
      </div>
      <div class="input-group reg-login-div">
                    <span class="input-group-addon icon-password" id="basic-addon2">
                    </span>
        <input v-model="password" name="password" type="password" class="form-control login-input" style="width: 262px"
               placeholder="密码" aria-describedby="basic-addon2">
        <input v-model="rememberTime" type="number" name="remember" hidden>
      </div>
      <button v-on:click="login" class="btn btn-primary" style="width: 300px;height: 42px;" type="button">
        登录
      </button>
    </div>
  </form>
</template>

<script>
  export default {
    data() {
      return {
        account: '',
        password: '',
        rememberTime: 7200
      }
    },
    methods:{
      login() {
        $.ajax({
          url : "http://123.206.80.54:7000/user/login",
          type : "POST",
          data : {
            account : this.account,  //username or mobile number
            password : this.password,
            remember : this.rememberTime  //(如果需要记住登录)登录记忆时长, 以秒(s)为单位
          },
          dataType: "json",
          success : function(status, error, res) {
            let expiresDate = new Date();
            expiresDate.setTime(expiresDate.getTime() + (2*60*60*1000));
            $.cookie('loginToken', res.responseJSON.res.loginToken, {path: '/', expires: expiresDate});
            this.$router.push('/index');
          }
      })
    }
  }}

</script>

<style>
  .icon-user {
    background-image: url(../../assets/images/reg-login/icon_user.png);
  }
  .icon-password {
    background-image: url(../../assets/images/reg-login/icon_password.png);
  }
</style>
